﻿using Qins.PluginInterface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace Qins.Plugins.ThrowError
{
    public class ThrowErrorPlugin : IPlugin
    {
        public string PluginName => "ThrowErrorPlugin";
        public string Description { get => "看看如果有异常的话主程序会不会崩溃"; }

        public string InDescription { get => "in a string."; }

        public string OutDescription { get => "return a string."; }

        public bool AutoRun { get => false; }

        public string Execute(object inPars)
        {
            try
            {
                MainWindow mainWindow = new MainWindow(this);
                mainWindow.Show();
                //string a = "abc";
                //int b = Convert.ToInt32(a);//字符串转int失败，抛出异常
                //Console.WriteLine(b);
                //Console.ReadKey();
                //throw new Exception("我就是弹个异常而已");
                //MessageBox.Show(inPars.ToString());
                return ("Hello!!!" + inPars?.ToString());
            }
            catch (Exception ex)
            {

                throw;
            }

        }

        public Message MessageTransport { get; set; }

        public void Initialization(Message messageTransport)
        {
            MessageTransport = messageTransport;
            MessageTransport.Receive += CallPluginRun;//绑定接收方法
        }

        public string CallPluginRun(string pluginName, MessageContent message)
        {            
            MessageTransport.SendMessage(pluginName, message);
            return "";
        }
    }
}
